import request from '@/utils/request'
import { Attr, AttrResponseData, CategoryResponseData } from './type'

// API接口枚举
enum API {
  c1_URL = '/admin/product/getCategory1', // 获取第一级分类的接口
  c2_URL = '/admin/product/getCategory2/', // 获取第二级分类的接口
  c3_URL = '/admin/product/getCategory3/', // 获取第三级分类的接口
  // 获取分类下已有的属性与属性值
  ATTR_URL = '/admin/product/attrInfoList/',
  // 添加或修改已有的属性接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  //删除某一个已有的属性
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

// 请求第一级分类接口
export const reqC1 = () => request.get<any, CategoryResponseData>(API.c1_URL)

// 请求第二级分类接口
export const reqC2 = (category1Id: number | string) => {
  return request.get<any, CategoryResponseData>(API.c2_URL + category1Id)
}

// 请求第三级分类接口
export const reqC3 = (category2Id: number | string) => {
  return request.get<any, CategoryResponseData>(API.c3_URL + category2Id)
}

// 获取对应分类下已有的属性与属性值接口
export const reqAttr = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number,
) => {
  return request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
}

// 添加或修改已有的属性接口
export const reqAddOrUpDateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

// 删除某一个已有的属性
export const reqDeleteAttr = (attrId: number) => {
  return request.delete<any, any>(API.DELETEATTR_URL + attrId)
}
